<template>
  <div class="h-contact">
    <div>
      <div class="clearfix padding h-top-title">
        <div class="float-l"><span class="bar-l"></span>通讯录</div>
        <div class="float-r">
        </div>
      </div>
      <div class="search-emp clearfix home-search-emp">
        <div class="float-l relative search-input">
          <div class="home-search-emp-icon border color" @click="showOrg"><i class="fas fa-sitemap"></i></div>
          <el-select
            v-model="userKeyWord"
            size="small"
            filterable
            remote
            default-first-option
            reserve-keyword
            placeholder="输入员工姓名/编号搜索"
            :remote-method="remoteMethod"
            @change="change"
            @focus="focus"
            :loading="loading">
            <el-option
              v-for="item in userOptions"
              :key="item.id"
              :label="item.name"
              :value="item.id">
            </el-option>
          </el-select>
        </div>
        <div class="clearfix float-l always-name">
          <div  class="float-l alert-title">常搜:</div>
          <div class="float-l always-name-item">
            <div class="float-l" v-for="item in historyData" :key="item.historyEmployeeNo" @click="infoRight = 0;getFindEmplInfo(item.historyEmployeeNo)">{{item.employeeName}}</div>
          </div>
        </div>
      </div>
      <bf-table-edit   ref="showOrgRefs" :title="'机构筛选'" @formSubmit="showOrgHidden">
        <div>
          <bf-org :userOrg="true" @nodeClick="nodeClick"></bf-org>
        </div>
      </bf-table-edit>
      <bf-table-edit :right="infoRight" :width="650"  ref="showInfo" :title="'联系人信息'" @formSubmit="formSubmit">
        <div>
          <div class="info-item clearfix">
            <div class="title"><img src="../../../../assets/beneform4j/icon/home_icon_id.png" alt=""> 员工编号</div>
            <div class="info-value">{{userInfoData.employeeNo}}</div>
          </div>
          <div class="info-item clearfix">
            <div  class="title"><img src="../../../../assets/beneform4j/icon/home_icon_sex.png" alt=""> 员工性别</div>
            <div class="info-value">{{userInfoData.sex == '1'?'男':'女' }}</div>
          </div>
          <div class="info-item clearfix">
            <div  class="title"><img src="../../../../assets/beneform4j/icon/home_icon_name.png" alt=""> 员工姓名</div>
            <div class="info-value">{{userInfoData.employeeName}}</div>
          </div>
          <div class="info-item clearfix">
            <div  class="title"><img src="../../../../assets/beneform4j/icon/home_icon_organization.png" alt=""> 所在机构</div>
            <div class="info-value">{{userInfoData.orgName}}</div>
          </div>
          <div class="info-item clearfix">
            <div  class="title"><img src="../../../../assets/beneform4j/icon/home_icon_post.png" alt=""> 任职岗位</div>
            <div class="info-value" >{{userInfoData.positionName}}</div>
          </div>
          <div class="info-item clearfix">
            <div  class="title"><img src="../../../../assets/beneform4j/icon/home_icon_v1.png" alt=""> 所属职级</div>
            <!-- <div class="info-value">{{userInfoData.postLevel}}</div> -->
            <div class="info-value"><span v-params="{code:'RANK', id: userInfoData.postLevel}"></span></div>
          </div>
          <div class="info-item clearfix">
            <div  class="title"><img src="../../../../assets/beneform4j/icon/home_icon_dress.png" alt=""> 工作地址</div>
            <!-- <div class="info-value">{{userInfoData.workAddree}}</div> -->
            <div class="info-value"><span v-params="{code:'WORKPLACE', id: userInfoData.workAddree}"></span></div>
          </div>
          <div class="info-item clearfix">
            <div  class="title"><img src="../../../../assets/beneform4j/icon/home_icon_mail.png" alt=""> 联系邮箱</div>
            <div class="info-value">{{userInfoData.companyEmail?userInfoData.companyEmail:'无'}}</div>
          </div>
          <div class="info-item clearfix">
            <div  class="title"><img src="../../../../assets/beneform4j/icon/home_icon_phone.png" alt=""> 联系手机</div>
            <div class="info-value">{{userInfoData.mobile?userInfoData.mobile: '无'}}</div>
          </div>
           <div class="info-item clearfix">
            <div  class="title"><img src="../../../../assets/beneform4j/icon/home_icon_ground.png" alt=""> 联系电话</div>
            <div class="info-value">{{userInfoData.workMobile?userInfoData.workMobile:'无'}}</div>
          </div>

          <div class="info-item clearfix">
            <div  class="title"><img src="../../../../assets/beneform4j/icon/home_icon_chat.png" alt=""> 微信号码</div>
            <div class="info-value">{{userInfoData.wechatNumber?userInfoData.wechatNumber:'无'}}</div>
          </div>
          <div class="info-item clearfix">
            <div  class="title"><img src="../../../../assets/beneform4j/icon/home_icon_qq.png" alt=""> QQ号码</div>
            <div class="info-value">{{userInfoData.qqNumber?userInfoData.qqNumber:'无'}}</div>
          </div>


        </div>
      </bf-table-edit>


    </div>

  </div>
</template>

<script>
import { searchListApi, getSearchHistoryApi, getFindEmplInfoApi, addEmpHistoryApi } from './api'
export default {
  data() {
    return {
      infoRight: 0,
      loading: false,
      userKeyWord: '',
      userOptions: [],
      timer: false,
      userInfoData: {},
      historyData: []
    }
  },
  mounted() {
    // this.searchList()
    this.getSearchHistory()
  },
  methods: {
    formSubmit() {
      this.$refs.showInfo.hidden()
      this.$refs.showOrgRefs.hidden()
      this.getSearchHistory()
    },
    addEmpHistory(employeeNo) {
      const params = {
        historyEmployeeNo: employeeNo
      }
      addEmpHistoryApi(params).then(response => {

      })
    },
    focus() {
      this.userKeyWord = ''
    },
    getFindEmplInfo(id) {
      const params = {
        historyEmployeeNo: id
      }
      getFindEmplInfoApi(params).then(response => {
        if (response.success) {
          if (response.data) {
            this.userInfoData = response.data
            this.addEmpHistory(id)
            this.$refs.showInfo.show({})
          }
        }
      })
    },
    getSearchHistory() {
      getSearchHistoryApi().then(resposne => {
        if (resposne.data) {
          this.historyData = resposne.data
          this.historyData.splice(2,1)
        }
      })
    },
    change(value) {
      this.infoRight = 0
      this.getFindEmplInfo(value)
    },
    remoteMethod(value) {
      if (value && value.length>0) {
        if (!this.loading) {
          this.searchList(value)
        }
      }

    },
    searchList(keyword) {
      const params = {
        historyEmployeeNo: keyword
      }
      this.loading = true
      searchListApi(params).then(resposne => {
        if (resposne.success) {
          this.loading = false
          if (resposne.data.length > 0) {
            this.userOptions = resposne.data
          } else {
            this.userOptions = []
          }
        }
      })
    },
    showOrg() {
      this.$refs.showOrgRefs.show({})
      // this.$refs.showInfo.show({})
    },
    nodeClick(node) {
      if (node.isEmployee === '1') {
        this.infoRight = 500
        this.getFindEmplInfo(node.id)
      }
    },
    showOrgHidden() {
      this.$refs.showOrgRefs.hidden()
    }
  }
}
</script>

<style scoped>
@import url('../home.css');
.info-item{
  padding-bottom: 40px;
  width: 50%;
  float: left;
}
.info-item>div{
  float: left;
}
.info-item>.title{
  width: 100px;
  margin-left: 40px;
}
.info-item>.title>img{
  position: relative;
  top: 2px;
  margin-right: 10px;
}
.always-name-item>div{
  float: left;
  overflow: hidden;
  white-space: nowrap;
  padding: 0;
  margin-right: 10px;
  text-overflow: ellipsis;
}
.home-search-emp .search-input{
  width: 45%;
}
.home-search-emp .always-name{
  width: 55%;
}
.always-name{
  display: flex;
  white-space: nowrap;
}
.h-contac{
  overflow: hidden;
}
.info-value{
  margin-left: 10px;
  height: 19px;
  line-height: 22px;
}
.home-search-emp-icon{
    position: absolute;
    top: 0;
    right: 0;
    width: 32px;
    height: 32px;
    text-align: center;
    line-height: 32px;
    background: #f5f7fa;
    color: #909399;
    border-top-right-radius: 4px;
    border-bottom-right-radius: 4px;
    cursor: pointer;

}
</style>


